#include "gtest/gtest.h"

#include "Graph.h"
#include "Prim.h"

class PrimTest : public ::testing::Test {
	protected:
		virtual void SetUp() {
		}
		virtual void TearDown() {
		}

	public:
};

TEST_F(PrimTest, MST_StartFrom0) {
	Graph g(5, false);
	g.addEdge(0, 1, 200);
	g.addEdge(0, 2, 100);
	g.addEdge(0, 4, 10);
	g.addEdge(1, 2, 20);
	g.addEdge(2, 4, 15);
	g.addEdge(2, 3, 5);

	PRIM sut(g);
	sut.computeMST(0);

	vector<int> expectedPred;
	expectedPred.push_back(-1);
	expectedPred.push_back(2);
	expectedPred.push_back(4);
	expectedPred.push_back(2);
	expectedPred.push_back(0);

	vector<int> expectedSelectedEdge;
	expectedSelectedEdge.push_back(0);
	expectedSelectedEdge.push_back(20);
	expectedSelectedEdge.push_back(15);
	expectedSelectedEdge.push_back(5);
	expectedSelectedEdge.push_back(10);

	ASSERT_EQ(expectedPred, sut.getPredecessor());
	ASSERT_EQ(expectedSelectedEdge, sut.getSelectedEdge());
}

TEST_F(PrimTest, MST_StartFrom2) {
	Graph g(5, false);
	g.addEdge(0, 1, 200);
	g.addEdge(0, 2, 100);
	g.addEdge(0, 4, 10);
	g.addEdge(1, 2, 20);
	g.addEdge(2, 4, 15);
	g.addEdge(2, 3, 5);

	PRIM sut(g);
	sut.computeMST(2);

	vector<int> expectedPred;
	expectedPred.push_back(4);
	expectedPred.push_back(2);
	expectedPred.push_back(-1);
	expectedPred.push_back(2);
	expectedPred.push_back(2);

	vector<int> expectedSelectedEdge;
	expectedSelectedEdge.push_back(10);
	expectedSelectedEdge.push_back(20);
	expectedSelectedEdge.push_back(0);
	expectedSelectedEdge.push_back(5);
	expectedSelectedEdge.push_back(15);

	ASSERT_EQ(expectedPred, sut.getPredecessor());
	ASSERT_EQ(expectedSelectedEdge, sut.getSelectedEdge());
}

